package regalloc;

import flowgraph.AssemFlowGraph;
import graph.Node;
import graph.NodeList;

import java.util.Dictionary;
import java.util.Hashtable;

import temp.Temp;
import temp.TempList;
import assem.Instr;

public class Liveness extends InterferenceGraph {

	private final Dictionary<Node<Instr>, TempList> liveMap = new Hashtable<Node<Instr>, TempList>();

	public Liveness(AssemFlowGraph flow) {

		NodeList<Node<Instr>> list = flow.nodes();

		for (int i = 0; i < list.size(); i++) {

			liveMap.put(list.head, liveInUnionOut(flow.liveIn.get(list.head), flow.liveOut.get(list.head)));
			list = list.tail;
			i = 0;
		}
	}

	private TempList liveInUnionOut(TempList liveIn, TempList liveOut) {
		TempList result = new TempList(liveIn.head, liveIn.tail);
		TempList list = result.tail;
		while (list.tail != null) {
			list = list.tail;
		}
		list.tail = new TempList(liveOut.head, liveOut.tail);

		return result;
	}

	@Override
	public Node tnode(Temp temp) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Temp gtemp(Node node) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public MoveList moves() {
		// TODO Auto-generated method stub
		return null;
	}

}
